﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Microsoft.AspNet.SignalR;
using System.Threading.Tasks;
using MegaBitProject.Models;

namespace MegaBitProject.Controllers
{
    // Chat function for Lobby in all games

    [Authorize]
    public class ChatHub : Hub
    {
        // When som1 join the hub
        public void Join(string groupID, string userName)
        {
            //Add new user to the group
            Groups.Add(Context.ConnectionId, groupID);
            // Tell other users that som1 has joined the hub
            Clients.OthersInGroup(groupID).userJoin(userName);
        }

        // Function that receive message from user and send it to all other in the group
        public void addMessage(string groupID, string userName, string message)
        {
            // Send that message to other users in the group
            Clients.OthersInGroup(groupID).newMessage(userName, message);
        }
    }
}